home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fmtline.exe / FMTLINE.PAS < prev   
Pascal/Delphi Source File  |  1993-02-14  |  33KB  |  989 lines

  1.   {*******************************************************}
  2.   {                                                       }
  3.   {       Turbo Pascal Version 6.0                        }
  4.   {    Optional FormLine Unit for use with Turbo Vision   }
  5.   {    Created and Copyright (c) 1991  J. John Sprenger   }
  6.   {                                                       }
  7.   {       Additional LatLong and Time formatlines         }
  8.   {       created by S.A. Midwinter 74670,1306            }
  9.   {*******************************************************}
  10.  
  11.   unit FmtLine;   {revised from Formline, use in its place}
  12.  
  13.   {$O+,F+,D+,R+,X+,S+}
  14.  
  15.   interface   {===========================================}
  16.  
  17.   uses
  18.  
  19.     {Turbo Pascal Run-Time Library Units}
  20.  
  21.     Crt,
  22.  
  23.     {Turbo Vision Standard Units}
  24.  
  25.     Objects, Drivers, Views, Dialogs, App,
  26.  
  27.     {Turbo Vision Accessory Units}
  28.  
  29.     StdDlg, MsgBox;
  30.  
  31.   const
  32.  
  33.     { flError, flCharOk and flFormatOK are constants used  }
  34.     { by tFormatLine.CheckPicture.  flError is returned    }
  35.     { when an error is found,  flCharOk when an character  }
  36.     { is found to be appropriate,  And flFormatOk when the }
  37.     { entire input string is found acceptable.             }
  38.     flError    = $0000;
  39.     flCharOK   = $0001;
  40.     flFormatOK = $0002;
  41.  
  42.     { flCharError is passed to tFormatLine.ReportError     }
  43.     { when a character does not fit the proper form.       }
  44.     { flFormatError is used when the format is not         }
  45.     { satisfied even though input so far is acceptable.    }
  46.     flCharError          = 1;
  47.     flFormatError        = 2;
  48.  
  49.     { CommandSet represents the characters used in Format  }
  50.     { Line Pictures.  These match those used by Paradox.   }
  51.     { For more information, refer to the Paradox user's    }
  52.     { manual, which has many examples of picture strings.  }
  53.  
  54.     CommandSet = [ '[', '{', '?', '&', '''', '!', '#', '{',
  55.                    ',', ']', '}', '*'];
  56.  
  57.   type
  58.  
  59.     { tFormatLine }
  60.     { tFormatLine is the improved tInputLine object which  }
  61.     { accepts Paradox-form Picture strings to ensure that  }
  62.     { data will be entered in an acceptable form.          }
  63.  
  64.     pFormatLine = ^tFormatLine;
  65.     tFormatLine = object(tInputLine)
  66.       Picture : string;
  67.       constructor Init(var Bounds : tRect;
  68.                        AMaxLen : integer; Pic : string);
  69.       function Valid(command : word) : boolean; virtual;
  70.       procedure HandleEvent(var Event : tEvent); virtual;
  71.       function CheckPicture(var s, Pic : string;
  72.                             var CPos : integer):word;
  73.       procedure ReportError( kind : word); virtual;
  74.     end;
  75.  
  76.     { tMoneyFormatLine }
  77.     { tMoneyFormatLine is an input line intended for use   }
  78.     { real number fields associated with money.  Input is  }
  79.     { preceded with a "$" sign and terminated with a "."   }
  80.     { followed by the appropriate fractional value.        }
  81.     pMoneyFormatLine = ^tMoneyFormatLine;
  82.     tMoneyFormatLine = object( tFormatLine )
  83.       constructor Init(var Bounds : tRect; AMaxlen : integer);
  84.       procedure SetData(var Rec); virtual;
  85.       procedure GetData(var Rec); virtual;
  86.       function DataSize : word; virtual;
  87.     end;
  88.  
  89.     { tPhoneFormatLine }
  90.     { tPhoneFormatLine is for phone number fields. Normal  }
  91.     { 10-digit numbers are entered in the following form   }
  92.     { (###) ###-####.  International numbers are entered   }
  93.     { digit after digit with spaces and hyphens where the  }
  94.     { user deems appropriate.                              }
  95.     pPhoneFormatLine = ^tPhoneFormatLine;
  96.     tPhoneFormatLine = object( tFormatLine )
  97.       constructor Init(var Bounds : tRect; AMaxLen : integer);
  98.       procedure SetData(var Rec); virtual;
  99.       procedure GetData(var Rec); virtual;
  100.     end;
  101.  
  102.     { tRealFormatLine }
  103.     { tRealFormatLine is used for real number fields.  It  }
  104.     { can handle both decimal and scientific notations.    }
  105.     pRealFormatLine = ^tRealFormatLine;
  106.     tRealFormatLine = object ( tFormatLine )
  107.       constructor Init(var Bounds : tRect; AMaxLen : integer);
  108.       procedure SetData(var Rec); virtual;
  109.       procedure GetData(var Rec); virtual;
  110.       function DataSize : word; virtual;
  111.     end;
  112.  
  113.     { tIntegerFormatLine }
  114.     { tIntegerFormatLine is used for integer fields.  It   }
  115.     { accepts signed integers.                             }
  116.     pIntegerFormatLine = ^tIntegerFormatLine;
  117.     tIntegerFormatLine = object( tFormatLine )
  118.       constructor Init(var Bounds : tRect; AMaxLen : integer);
  119.       procedure SetData(var Rec); virtual;
  120.       procedure GetData(var Rec); virtual;
  121.       function DataSize : word; virtual;
  122.     end;
  123.  
  124.     { tNameFormatLine }
  125.     { tNameFormatLine accepts words and capitalizes the    }
  126.     { first character of each word.  This would be used    }
  127.     { proper names and addresses.                          }
  128.     pNameFormatLine = ^tNameFormatLine;
  129.     tNameFormatLine = object( tFormatLine )
  130.       constructor Init(var Bounds : tRect; AMaxLen : integer);
  131.     end;
  132.  
  133.     { tZipFormatLine }
  134.     { tZipFormatLine is used for ZIP and Postal Code       }
  135.     { fields.  It handles U.S. and Canadian format codes.  }
  136.     pZipFormatLine = ^tZipFormatLine;
  137.     tZipFormatLine = object( tFormatLine )
  138.       constructor Init(var Bounds : tRect; AMaxLen : integer);
  139.       end;
  140.  
  141.     { tLatLongFormatLine }      {added by Stewart Midwinter}
  142.     { tLatLongFormatLine is used for geographical coor-    }
  143.     { dinates entered in fields.  It can handle HH.hhhh    }
  144.     { and HH:MM:SS.ss notations.                           }
  145.     { Limit is 90 for Latitudes and 180 for Longitudes     }
  146.  
  147.     pLatLongFormatLine = ^tLatLongFormatLine;
  148.     tLatLongFormatLine = object ( tFormatLine )
  149.       constructor Init(var Bounds: tRect; AMaxLen: integer);
  150.       procedure SetData(var Rec); virtual;
  151.       procedure GetData(var Rec); virtual;  {NOTE: sends back a real; dialog record must be real}
  152.       function DataSize : word; virtual;
  153.     end;
  154.  
  155.     { the Lat object has a limit of 90 degrees, while the }
  156.     { LatLong object has a limit of 180 degrees.  This    }
  157.     { means that Lat allows only 2 digits before the deci-}
  158.     { mal, while Long allows three digits before the deci-}
  159.     { mal. To make it easier to validate, the Lat is limi-}
  160.     { ted to 89.9999 and Long to 179.9999 degrees.        }
  161.     { note: Lat requires 2 and Long 3 digit before decimal}
  162.     { tLatFormatLine }
  163.     pLatFormatLine = ^tLatFormatLine;
  164.     tLatFormatLine = object ( tLatLongFormatLine )
  165.       constructor Init(var Bounds: tRect; AMaxLen: integer);
  166.       procedure SetData(var Rec); virtual;
  167.     end;
  168.  
  169.     { tLongFormatLine }
  170.     pLongFormatLine = ^tLongFormatLine;
  171.     tLongFormatLine = object ( tLatLongFormatLine )
  172.       constructor Init(var Bounds: tRect; AMaxLen: integer);
  173.     end;
  174.  
  175.     { tTimeFormatLine is a descendant of LatLongFormatLine, since the}
  176.     { notation is similar. The only difference is that times are lim-}
  177.     { ited to 24 hours and latitudes to 90 degrees; the minutes and  }
  178.     { seconds and hundredths are the same.                           }
  179.     { tTimeFormatLine can handle HH.hhhh or HH:MM:SS.ss formats      }
  180.  
  181.     { tTimeFormatLine }
  182.     pTimeFormatLine = ^tTimeFormatLine;
  183.     tTimeFormatLine = object ( tLatLongFormatLine )
  184.       constructor Init(var Bounds: tRect; AMaxLen: integer);
  185.     end;
  186.  
  187.   implementation {=========================================}
  188.  
  189.   { Function Copy represents a bit of syntactic sugar for  }
  190.   { the benefit of the author.  It changes the Copy func.  }
  191.   { so that its parameters represent start and end points  }
  192.   { rather than a start point followed by a quantity.      }
  193.   function Copy(s : string; start, stop : integer) : string;
  194.   begin
  195.     if stop < start then Copy:=''
  196.     else Copy:=System.Copy(s,start,stop-start+1);
  197.   end;
  198.  
  199.   { Function FindMatch recursively locates the matching   }
  200.   { grouping characters for "{" and "[".                  }
  201.   function FindMatch(P : string) : integer;
  202.   var
  203.     i:integer;
  204.     match:boolean;
  205.     c:char;